package com.example.codegenerator.handler.generator;

import com.example.codegenerator.common.config.GeneratorConfig;
import com.example.codegenerator.common.config.TemplateConfig;
import com.example.codegenerator.common.constant.file.PathInfoConstant;
import com.example.codegenerator.common.constant.obj.GeneratorBeanNameConstant;
import com.example.codegenerator.common.constant.obj.GeneratorMapConstant;
import com.example.codegenerator.common.sources.GeneratorEngine;
import com.example.codegenerator.service.GeneratorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 构建接口层
 *
 * @author lvshengyu
 * @date 2023/8/16
 */
@SuppressWarnings("all")
@Slf4j
@Service(GeneratorBeanNameConstant.CONTROLLER_API)
public class GeneratorControllerApiHandler implements GeneratorService {

    @Autowired
    private GeneratorEngine generatorEngine;

    @Autowired
    private GeneratorConfig generatorConfig;

    /**
     * 生成代码
     *
     * @param dataMap 代码生成填充信息
     * @return
     */
    @Override
    public Boolean generator(Map<String, Object> dataMap) {
        log.info("==================== 开始构建controllerApi代码 ====================");
        String path = generatorConfig.initPathInfo().get(PathInfoConstant.CONTROLLER_API_PATH);
        generatorEngine.mkdir(path).outPrint(dataMap, GeneratorMapConstant.CONTROLLER_API_NAME, PathInfoConstant.CONTROLLER_API_PATH, TemplateConfig.getInstance().getControllerApi());
        log.info("==================== controllerApi代码构建完成 ====================");
        return Boolean.TRUE;
    }
}
